'use strict';

const { DataTypes } = require('sequelize');
const sequelize = require('../../database/sequelize');

/**
 * 游记点赞模型
 */
const TravelNoteLike = sequelize.define(
  'TravelNoteLike',
  {
    id: {
      type: DataTypes.INTEGER,
      primaryKey: true,
      autoIncrement: true,
      comment: '点赞ID'
    },
    note_id: {
      type: DataTypes.INTEGER,
      allowNull: false,
      comment: '游记ID',
      field: 'note_id'
    },
    user_id: {
      type: DataTypes.INTEGER,
      allowNull: false,
      comment: '用户ID',
      field: 'user_id'
    },
    created_at: {
      type: DataTypes.DATE,
      allowNull: false,
      defaultValue: DataTypes.NOW,
      comment: '创建时间',
      field: 'created_at'
    }
  },
  {
    tableName: 'travel_note_likes',
    timestamps: false,
    underscored: true,
    indexes: [
      {
        name: 'idx_note_user',
        unique: true,
        fields: ['note_id', 'user_id']
      },
      {
        name: 'idx_user_id',
        fields: ['user_id']
      }
    ]
  }
);

/**
 * 游记收藏模型
 */
const TravelNoteFavorite = sequelize.define(
  'TravelNoteFavorite',
  {
    id: {
      type: DataTypes.INTEGER,
      primaryKey: true,
      autoIncrement: true,
      comment: '收藏ID'
    },
    note_id: {
      type: DataTypes.INTEGER,
      allowNull: false,
      comment: '游记ID',
      field: 'note_id'
    },
    user_id: {
      type: DataTypes.INTEGER,
      allowNull: false,
      comment: '用户ID',
      field: 'user_id'
    },
    created_at: {
      type: DataTypes.DATE,
      allowNull: false,
      defaultValue: DataTypes.NOW,
      comment: '创建时间',
      field: 'created_at'
    }
  },
  {
    tableName: 'travel_note_favorites',
    timestamps: false,
    underscored: true,
    indexes: [
      {
        name: 'idx_note_user',
        unique: true,
        fields: ['note_id', 'user_id']
      },
      {
        name: 'idx_user_id',
        fields: ['user_id']
      }
    ]
  }
);

module.exports = {
  TravelNoteLike,
  TravelNoteFavorite
};

